﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DA
{
    public class danhsachmonhoc: ConnectData
    {
        public DataTable LayDSMonHoc()
        {
            string sql = "select MAMH, TENMH from MONHOC" ;
            return LayDatatable(sql);
        }
        DataLINQHocSinhDataContext dt = new DataLINQHocSinhDataContext();

        public List<MONHOC> layallmonhoc()
        {
            return dt.MONHOCs.ToList();
        }
        public bool ktramonhoc(MONHOC mh)
        {
            var query = from p in dt.MONHOCs
                        where p.MAMH == mh.MAMH
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public void themmonhoc(MONHOC mh)
        {
            MONHOC a = new MONHOC();
            a.MAMH = mh.MAMH;
            a.TENMH = mh.TENMH;

            dt.MONHOCs.InsertOnSubmit(a);
            dt.SubmitChanges();
        }
        public void xoamonhoc(MONHOC mh)
        {
            var query = from p in dt.MONHOCs
                        where p.MAMH == mh.MAMH
                        select p;
            dt.MONHOCs.DeleteAllOnSubmit(query);
            dt.SubmitChanges();
        }
        public void suamonhoc(MONHOC mh)
        {
            MONHOC a = dt.MONHOCs.Single(p => p.MAMH == mh.MAMH);
            a.MAMH = mh.MAMH;
            a.TENMH = mh.TENMH;
            dt.SubmitChanges();
        }
    }
}
